package com.example.transformer.controller;

import com.example.transformer.entity.ScanTask;
import com.example.transformer.repository.ScanTaskRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DatabaseTestController {

    @Autowired
    private ScanTaskRepository scanTaskRepository;

    @GetMapping("/test-db")
    public String testDatabase() {
        try {
            // 创建测试记录
            ScanTask testTask = new ScanTask("test.java", "public class Test {}");
            scanTaskRepository.save(testTask);

            // 查询记录数量
            long count = scanTaskRepository.count();

            return "数据库连接成功！当前扫描任务数量: " + count;
        } catch (Exception e) {
            return "数据库连接失败: " + e.getMessage();
        }
    }
}
